import { ResourceInfo } from "./ResourceInfo";
//class SWFInfo
    
    export  class SWFInfo extends ResourceInfo
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public get clip(): Object /* flash.display.MovieClip */
        {
            return this._clip;
        }

        public get bitmapData(): Object /* flash.display.BitmapData */
        {
            var loc1=null;
            if (this._bitmapData == null && this._clip) 
            {
                this._clip.gotoAndStop(1);
                loc1 = this._clip.getBounds(this._clip);
                if (!(loc1.height == 0 || loc1.width == 0)) 
                {
                    this._bitmapData = new Object /* flash.display.BitmapData */(loc1.width, loc1.height, true, 0);
                    this._bitmapData.draw(this._clip, new Object /* flash.geom.Matrix */(1, 0, 0, 1, -loc1.x, -loc1.y), null, null, null, false);
                    this._clip = null;
                }
            }
            return this._bitmapData;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (arg1 is flash.display.MovieClip) 
            {
                this._clip = arg1 as Object /* flash.display.MovieClip */;
                this._appDomain = this._clip.loaderInfo.applicationDomain;
            }
            else if (arg1 is flash.display.LoaderInfo) 
            {
                loaderInfo = arg1 as Object /* flash.display.LoaderInfo */;
                this._appDomain = loaderInfo.applicationDomain;
                if (loaderInfo.swfVersion >= 9) 
                {
                    this._clip = loaderInfo.content as Object /* flash.display.MovieClip */;
                }
                else 
                {
                    throw new Error(loaderInfo.url + "版本：" + loaderInfo.swfVersion);
                }
            }
            if (this._clip) 
            {
                this._clip.gotoAndStop(1);
            }
            return;
        }

        public getAssetClass(arg1: string): Class
        {
            if (null == this._appDomain) 
            {
                throw new Error("not initialized");
            }
            if (this._appDomain.hasDefinition(arg1)) 
            {
                return this._appDomain.getDefinition(arg1) as Class;
            }
            return null;
        }

        public /* override */ dispose(): void
        {
            isLoaded = false;
            isLoading = false;
            this._clip = null;
            this._appDomain = null;
            if (this._bitmapData) 
            {
                this._bitmapData.dispose();
                this._bitmapData = null;
            }
            super.dispose();
            return;
        }

        protected /* override */ unload(arg1: Object /* flash.display.LoaderInfo */): void
        {
            arg1.loader.unloadAndStop();
            super.unload(arg1);
            return;
        }

        private /* var */_clip: Object /* flash.display.MovieClip */;

        private /* var */_bitmapData: Object /* flash.display.BitmapData */;

        private /* var */_appDomain: Object /* flash.system.ApplicationDomain */;
    }
